﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SuCasa.DataAccess;
using SuCasa.Infrastructure;

namespace SuCasa.Controllers
{
    public class AssignmentController : Controller
    {
        readonly IMemberRepository _memberRepository;

        public AssignmentController()
        {
            if (Constants.UseFakes)
            {
                _memberRepository = new FakeMemberRepository();
            }
            else
            {
                _memberRepository = new MemberRepository(SuCasaContext.Instance);
            }
        }

        [HttpGet]
        public ActionResult List(int memberId, int courseId)
        {
            var member = _memberRepository.GetMemberBy(x => x.MemberId == memberId);
            if (member == null)
                return View("Error");
            else
            {
                var assignments = member.Assignments.Where(x => x.Assignment.CourseId == courseId);
                return View(assignments);
            }
            return View();
        }

    }
}
